﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using DataLayer.Model.Objects;

namespace DataLayer.Model.Classes
{
    [DataContract]
    [KnownType(typeof(Human))]
    [KnownType(typeof(Elf))]
    [KnownType(typeof(DarkElf))]
    [KnownType(typeof(Orc))]
    [KnownType(typeof(Dwarw))]
    public abstract class Character
    {
        private const int MAX_LEVEL = 80;
        private int _level;
    
        [DataMember]
        public List<Skill> Skills;

        [DataMember]
        public int Level{
            get { return _level; }
            set { 
                _level = value;
                UpdateSkills();
            }
        }

        protected Character()
        {
            Skills = new List<Skill>();
        }
        public void AddSkillToList(Skill pSkill)
        {
            if (Skills == null)
                Skills = new List<Skill>();
            Skills.Add(pSkill);
        }

        private void UpdateSkills()
        {
            var pSkills = Singleton.ReadClassSkills(this.GetType());
                foreach (var skill in pSkills)
                    if (skill.AccessLevel < _level)
                        AddSkillToList(skill);
        }
    }
}
